<?php
namespace Home\Controller;
use Think\Controller;

class LocationController extends Controller
{
     function returnSquarePoint($lng, $lat,$distance = 0.5)
        {
            define(EARTH_RADIUS, 6371);
            $dlng =  2 * asin(sin($distance / (2 * EARTH_RADIUS)) / cos(deg2rad($lat)));
            $dlng = rad2deg($dlng);
             
            $dlat = $distance/EARTH_RADIUS;
            $dlat = rad2deg($dlat);
             
                return array(
                            'left-top'=>array('lat'=>$lat + $dlat,'lng'=>$lng-$dlng),
                            'right-top'=>array('lat'=>$lat + $dlat, 'lng'=>$lng + $dlng),
                            'left-bottom'=>array('lat'=>$lat - $dlat, 'lng'=>$lng - $dlng),
                            'right-bottom'=>array('lat'=>$lat - $dlat, 'lng'=>$lng + $dlng)
                            );
        }
}